import torch
device = torch.device('cuda')
def tensor_transform(tensor, jacobi):

    MA = torch.tensor([[torch.square(jacobi[0, 0]), torch.square(jacobi[0, 1]), torch.square(jacobi[0, 2]),
                        jacobi[0, 0] * jacobi[0, 1], jacobi[0, 1] * jacobi[0, 2], jacobi[0, 0] * jacobi[0, 2]],
                       [torch.square(jacobi[1, 0]), torch.square(jacobi[1, 1]), torch.square(jacobi[1, 2]),
                        jacobi[1, 0] * jacobi[1, 1], jacobi[1, 1] * jacobi[1, 2], jacobi[1, 0] * jacobi[1, 2]],
                       [torch.square(jacobi[2, 0]), torch.square(jacobi[2, 1]), torch.square(jacobi[2, 2]),
                        jacobi[2, 0] * jacobi[2, 1], jacobi[2, 1] * jacobi[2, 2], jacobi[2, 0] * jacobi[2, 2]],
                       [2 * jacobi[0, 0] * jacobi[1, 0], 2 * jacobi[0, 1] * jacobi[1, 1],
                        2 * jacobi[0, 2] * jacobi[1, 2], jacobi[0, 0] * jacobi[1, 1] + jacobi[0, 1] * jacobi[1, 0],
                        jacobi[0, 1] * jacobi[1, 2] + jacobi[0, 2] * jacobi[1, 1],
                        jacobi[0, 0] * jacobi[1, 2] + jacobi[0, 2] * jacobi[1, 0]],
                       [2 * jacobi[1, 0] * jacobi[2, 0], 2 * jacobi[1, 1] * jacobi[2, 1],
                        2 * jacobi[1, 2] * jacobi[2, 2], jacobi[0, 1] * jacobi[2, 1] + jacobi[1, 1] * jacobi[2, 0],
                        jacobi[1, 1] * jacobi[2, 2] + jacobi[1, 2] * jacobi[2, 1],
                        jacobi[1, 0] * jacobi[2, 2] + jacobi[1, 2] * jacobi[2, 0]],
                       [2 * jacobi[2, 0] * jacobi[0, 0], 2 * jacobi[2, 1] * jacobi[0, 1],
                        2 * jacobi[2, 2] * jacobi[0, 2], jacobi[2, 0] * jacobi[0, 1] + jacobi[2, 1] * jacobi[0, 0],
                        jacobi[2, 1] * jacobi[0, 2] + jacobi[2, 2] * jacobi[0, 1],
                        jacobi[2, 0] * jacobi[0, 2] + jacobi[2, 2] * jacobi[0, 0]],
                       ], dtype=torch.float, device=device)
                       
    return MA.t() @ tensor.float().to(device) @ MA